from selenium.webdriver.common.by import By
from base.mis.base import BasePage, BaseHandle
class LoginPage(BasePage):
    def __init__(self):
        super().__init__()
        self.username=By.XPATH,'//*[@id="app"]/div/form/input[1]'
        self.password=By.XPATH,'//*[@id="app"]/div/form/input[2]'
        self.login_btn=By.XPATH,'//*[@id="inp1"]'
    def find_username(self):
        return self.get_element(self.username)
    def find_password(self):
        return self.get_element(self.password)
    def find_login_btn(self):
        return self.get_element(self.login_btn)
class LoginHandle(BaseHandle):
    def __init__(self):
        self.login_page=LoginPage()
    def input_username(self,username):
        self.input_text(self.login_page.find_username(),username)
    def input_password(self,password):
        self.input_text(self.login_page.find_password(),password)
    def click_login_btn(self):
        js="document.getElementById('inp1').removeAttribute('disabled')"
        self.login_page.driver.execute_script(js)
        self.login_page.find_login_btn().click()
class LoginProxy:
    def __init__(self):
        self.login_handle=LoginHandle()
    def login(self,username,password):
        self.login_handle.input_username(username)
        self.login_handle.input_password(password)
        self.login_handle.click_login_btn()

